#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
ll n,m;const ll N = 3e5+10;
ll ans = 0, cnt = 0;
ll h[N], e[N], ne[N],d[N], idx;
void topsort()
{
    queue<ll> q;
    for(ll i=1;i<=n;i++)
    {
        if(d[i]==1)
        {
            q.push(i);
        }
    }
    while(!q.empty())
    {
        auto a=q.front();
        q.pop();
        d[a]--;
        for(ll i=h[a];i!=-1;i=ne[i])
        {
            ll b = e[i];
            d[b]--;
            if(d[b]==1)
            {
                q.push(b);
            }
        }
    }
}
void add(ll a,ll b)
{
    e[idx]=b;
    ne[idx]=h[a];
    h[a] = idx++;
}
void dfs(ll u)
{
    d[u]=0;
    cnt++;
    for(ll i=h[u];i!=-1;i=ne[i])
    {
        ll now = e[i];
        if(d[now]!=0)
        {
            dfs(now);
        }
    }
}
void solve()
{
    idx = 0;
    memset(h,-1,sizeof h);
    memset(d, 0, sizeof d);
    cin >> n >> m;
    for(ll i=1;i<=m;i++)
    {
        ll a,b;
        cin >> a >> b;
        add(a,b),add(b,a);
        d[a]++, d[b]++;
    }

    topsort();

    for(ll i=1;i<=n;i++)
    {
        if(d[i]>0&&d[i]!=2)
        {
            dfs(i);
        }
    }

    ans = cnt = 0;
    for(ll i=1;i<=n;i++)
    {
        if(d[i]==2)
        {
            dfs(i);
            ans++;
        }
    }
    if(ans==1)
    {
        cout << "Yes" << " " << cnt << endl;
    }
    else {
        cout << "No " << ans << endl;
    }
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
